﻿using BAASearchLib;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System;

namespace TestProject
{


    [TestClass()]
    public class CompareDateModifiedTest
    {
        private static FileInfo txtFile;
        private static DateTime modifiedDate;
        private static DateTime createdDate;
        private static FileComparer comparer;

        private TestContext testContextInstance;

        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        
        [ClassInitialize()]
        public static void ClassInitializer(TestContext testContext)
        {
            txtFile = new FileInfo(@"C:\TestData\TextFile.txt");

            modifiedDate = txtFile.LastWriteTime;
            createdDate = txtFile.CreationTime;
        }

        [TestMethod()]
        public void FindCorrectModifiedDate()
        {
            comparer = new CompareDateModified(modifiedDate);
            Assert.IsTrue(comparer.Compare(txtFile));

            comparer = new CompareDateModified(modifiedDate.AddHours(1));
            Assert.IsTrue(comparer.Compare(txtFile));

            comparer = new CompareDateModified(modifiedDate.AddHours(-1));
            Assert.IsTrue(comparer.Compare(txtFile));
        }

        [TestMethod()]
        public void FindBadModifiedDate()
        {
            comparer = new CompareDateModified(modifiedDate.AddDays(1));
            Assert.IsFalse(comparer.Compare(txtFile));

            comparer = new CompareDateModified(modifiedDate.AddYears(1));
            Assert.IsFalse(comparer.Compare(txtFile));

            comparer = new CompareDateModified(modifiedDate.AddDays(-1));
            Assert.IsFalse(comparer.Compare(txtFile));

            comparer = new CompareDateModified(modifiedDate.AddYears(-1));
            Assert.IsFalse(comparer.Compare(txtFile));
        }

        [TestMethod()]
        public void FindBeforeModifiedDate()
        {
            comparer = new CompareDateModified(createdDate.AddDays(1), DatePeriod.Before);
            Assert.IsTrue(comparer.Compare(txtFile));

            comparer = new CompareDateModified(createdDate.AddYears(1), DatePeriod.Before);
            Assert.IsTrue(comparer.Compare(txtFile));

            comparer = new CompareDateModified(createdDate, DatePeriod.Before);
            Assert.IsFalse(comparer.Compare(txtFile));

            comparer = new CompareDateModified(createdDate.AddHours(1), DatePeriod.Before);
            Assert.IsFalse(comparer.Compare(txtFile));

            comparer = new CompareDateModified(createdDate.AddDays(-1), DatePeriod.Before);
            Assert.IsFalse(comparer.Compare(txtFile));

            comparer = new CompareDateModified(createdDate.AddYears(-1), DatePeriod.Before);
            Assert.IsFalse(comparer.Compare(txtFile));
        }

        [TestMethod()]
        public void FindAfterModifiedDate()
        {
            comparer = new CompareDateModified(createdDate.AddDays(-1), DatePeriod.After);
            Assert.IsTrue(comparer.Compare(txtFile));

            comparer = new CompareDateModified(createdDate.AddYears(-1), DatePeriod.After);
            Assert.IsTrue(comparer.Compare(txtFile));

            comparer = new CompareDateModified(createdDate, DatePeriod.After);
            Assert.IsFalse(comparer.Compare(txtFile));

            comparer = new CompareDateModified(createdDate.AddHours(1), DatePeriod.After);
            Assert.IsFalse(comparer.Compare(txtFile));

            comparer = new CompareDateModified(createdDate.AddDays(1), DatePeriod.After);
            Assert.IsFalse(comparer.Compare(txtFile));

            comparer = new CompareDateModified(createdDate.AddYears(1), DatePeriod.After);
            Assert.IsFalse(comparer.Compare(txtFile));
        }
    }
}
